import unittest
from stack import *
from queue import *
from deque import *
from linked_list import *
class Test(unittest.TestCase):
    '''Test Exercise 10.1-2'''
    def test_dual_stack(self):
        print '#############BEGIN:test_dual_stack##################'
        #initialization
        dualStack = DualArrayStack(4)#size ==4
        dualStack.push2FirstStack(1)
        dualStack.push2FirstStack(11)
        dualStack.push2SecondStack(2)
        dualStack.push2SecondStack(22)
        
        #test overflows
        self.assertEqual(dualStack.push2FirstStack(3),None)
        self.assertEqual(dualStack.push2FirstStack(4),None)
        
        #test underflows
        self.assertEqual(dualStack.popFirstStack(), 11)
        self.assertEqual(dualStack.popFirstStack(), 1)
        self.assertEqual(dualStack.popFirstStack(), None)
        self.assertEqual(dualStack.popSecondStack(), 22)
        self.assertEqual(dualStack.popSecondStack(), 2)
        self.assertEqual(dualStack.popSecondStack(), None)
        print '#############END:test_dual_stack##################'
        
    def test_array_queue(self):
        
        print '#############BEGIN:test_array_queue##################'
        #initialization
        queue = ArrayQueue(4)
        queue.enqueue(1)
        queue.enqueue(2)
        queue.enqueue(3)
        queue.enqueue(4)
        
        #test overflows
        self.assertEqual(queue.enqueue(5), None)
        
        #test underflows
        self.assertEqual(queue.dequeue(), 1)
        self.assertEqual(queue.dequeue(), 2)
        self.assertEqual(queue.dequeue(), 3)
        self.assertEqual(queue.dequeue(), 4)
        self.assertEqual(queue.dequeue(), None)
        print '#############END:test_array_queue##################'   
    '''Exercise 10.1-5'''
    def test_deque(self):
        
        print '#############BEGIN:test_deque##################'
        #initialization
        deque = ArrayDeque(4)
        deque.insertAtHead(1)
        deque.insertAtTail(2)
        deque.insertAtHead(3)
        deque.insertAtTail(4)
        #test overflows
        self.assertEqual(deque.insertAtHead(6), None)
        
        #test underflows
        self.assertEqual(deque.deleteAtHead(), 3)
        self.assertEqual(deque.deleteAtHead(), 1)
        self.assertEqual(deque.deleteAtHead(), 2)
        self.assertEqual(deque.deleteAtTail(), 4)
        print '#############END:test_deque##################'   
    '''Exercise 10.2-1'''
    def test_list(self):
        print '#############BEGIN:test_list##################'
        linked_list = SinglyLinkedList()
        linked_list.insert(3)
        linked_list.insert(4)
        linked_list.insert(5)
        self.assertEqual(linked_list.count,3)
        
        self.assertEqual(linked_list.delete(4), 4)
        self.assertEqual(linked_list.count,2)
        print '#############END:test_list##################'
        
    '''Exercise 10.2-2'''
    def test_singly_list_stack(self):
        print '#############BEGIN:test_singly_list_stack##################'
        singly_list_stack = SinglyLinkedStack()
        singly_list_stack.push(2)
        singly_list_stack.push(3)
        singly_list_stack.push(4)
        
        self.assertEqual(singly_list_stack.pop(),4)
        self.assertEqual(singly_list_stack.pop(),3)
        self.assertEqual(singly_list_stack.pop(),2)
        print '#############END:test_singly_list_stack##################'
        
    '''Exercise 10.2-3'''
    def test_singly_list_queue(self):
        print '#############BEGIN:test_singly_list_queue##################'
        singly_list_queue = SinglyLinkedQueue()
        singly_list_queue.enqueue(2)
        singly_list_queue.enqueue(3)
        singly_list_queue.enqueue(4)
        
        self.assertEqual(singly_list_queue.dequeue(),2)
        self.assertEqual(singly_list_queue.dequeue(),3)
        self.assertEqual(singly_list_queue.dequeue(),4)
        print '#############END:test_singly_list_queue##################'
'''Main Entry'''
if __name__ == '__main__':
    unittest.main()
